package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//订单确认页需要的数据

public class OrderConfirmVo {
    //收获地址信息
    private List<MemberAddressVo> address;
    //所有订单项信息
    private List<OrderItemVo> items;
    @Setter @Getter
    Map<Long,Boolean> stocks;
    @Override
    public String toString() {
        return "OrderConfirmVo{" +
                "address=" + address +
                ", items=" + items +
                ", integration=" + integration +
                ", orderToken='" + orderToken + '\'' +
                '}';
    }

    //优惠券信息
    private Integer integration;
    //订单项的价格信息
//    private BigDecimal total;
    //防重令牌
    @Getter @Setter
    String orderToken;


        public Integer getCount(){
            Integer i=0;
            if (items!=null){
                for (OrderItemVo item : items) {
                   i+=item.getCount();
                }

            }
            return i;
        }
    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum= sum.add(multiply);
            }
        }
        return sum;
    }


    public BigDecimal getPay() {
        return getTotal();
    }

    //应付金额
   // private BigDecimal payPrice;
}
